package com.study.web.controller.student;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.app.domain.AppUser;
import com.study.app.domain.bo.AppUserStudentBo;
import com.study.app.service.IAppUserService;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.domain.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/student")
public class AppStudentController extends AppBaseController {

    private final IAppUserService appUserService;

    /**
     * 用户创建学生账号
     *
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/create")
    public R<Void> studentAccount(@RequestBody @Valid AppUserStudentBo bo) {
        return toAjax(appUserService.createStudyAccount(bo, getUserId()));
    }

    /**
     * 用户修改学生基本信息
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/updateInfo")
    public R<Void>studentUpdate(@RequestBody @Valid AppUserStudentBo bo){
        return toAjax(appUserService.updateStentInfo(bo));
    }

    /**
     * 获取当前家长名下孩子信息
     * @return
     */
    @SaCheckLogin
    @GetMapping("/list")
    public R<List<AppUser>> studentList() throws Exception {
        return R.ok(appUserService.quertStudentList(getUserId()));
    }

    /**
     * 修改孩子帐号状态
     * @param id
     * @param status
     * @return
     */
    @SaCheckLogin
    @GetMapping("/updateStatus")
    public R<Void>studentStatus(Long id,int status){
        return toAjax(appUserService.updateStudent(id,status));
    }
}
